function fitting = FitXe129FID(~, signal, varargin)
    p=inputParser; p.KeepUnmatched = true;
    p.addParameter('rate', 2e3, @(x) x>0);
    p.addParameter('targetResolution', 1e-3, @(x) x>0.0)
    p.addParameter('guessFrequency', 253.0, @(x) x>0.0);
    p.addParameter('oversamfac', 4, @(x) ~rem(x,1));
    p.addParameter('isPlot',false,@islogical);
    p.parse(varargin{:});
    
    fidSignal = signal.getNodeData(1);
    fidEnvelope = signal.getNodeData(2);

%     [~, idx] = findpeaks(abs(diff(diff(fidEnvelope.y))), 'NPeaks', 1, 'SortStr', 'descend');
%     idx = sum(fidEnvelope.x<=2.0);
    idx = 1;
    
    [xData, yData] = prepareCurveData( fidEnvelope.x(idx:end), fidEnvelope.y(idx:end) );
    ft = fittype( 'exp1' );
    opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
    opts.Display = 'Off';
    opts.StartPoint = [max(yData) -mean(xData)];

    [fitting.result, fitting.gof] = fit( xData, yData, ft, opts );
%     [fitting.result, fitting.gof] = fit( xData, yData, ft, opts );
    fitting.amplitude = fitting.result.a;
    fitting.tau = abs(1.0/fitting.result.b);

    %% need check for A
%     [P1,fList] = plomb(fidSignal.y,p.Results.rate,1000,p.Results.oversamfac);
        [P1,fList] = plomb(fidSignal.y,fidSignal.x,[],p.Results.oversamfac,'psd');
    fitting.fft.value = P1;
    fitting.fft.fList = fList;
    idx = (fList > p.Results.guessFrequency-2.0 & fList < p.Results.guessFrequency+2.0);
%     [fitting.fft.peak, fitting.fft.center, fitting.fft.width] = findpeaks(fitting.fft.value(idx), fitting.fft.fList(idx), 'NPeaks', 1, 'SortStr', 'descend');
    [fpeak, fcenter, fwidth] = findpeaks(fitting.fft.value(idx), fitting.fft.fList(idx), 'NPeaks', 1, 'SortStr', 'descend');    
    [xData, yData] = prepareCurveData( fList(and(fList<(fcenter+5*fwidth) , fList>(fcenter-5*fwidth))), ...
                sqrt(P1(and(fList<(fcenter+5*fwidth) , fList>(fcenter-5*fwidth)))) );
            
    ft = fittype( 'A/sqrt((x-cf)^2+w^2)+bg', 'independent', 'x', 'dependent', 'y' );
    opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
    opts.Display = 'Off';
    opts.StartPoint = [sqrt(fpeak)*fwidth 0 fcenter fwidth];
    opts.Lower = [0 0 fcenter-1 0];
    opts.Upper = [Inf Inf fcenter+1 0.1];
    opts.TolFun = 1e-16;
    opts.TolX = 1e-16;
    
    [fitting.resultF129, fitting.goff129] = fit( xData, yData, ft, opts );
    fitting.f129 = fitting.resultF129.cf;
    fitting.fft.center = fitting.resultF129.cf;
    fitting.fft.width = fitting.resultF129.w;
    fitting.fft.peak = (fitting.resultF129.A/fitting.resultF129.w+fitting.resultF129.bg);
    if p.Results.isPlot
        figure( 'Name', 'untitled fit 1' );
        h = plot( fitting.resultF129, xData, yData );grid on;
    end
end
